package com.gm;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-12-24
 * Time: 下午4:33
 * To change this template use File | Settings | File Templates.
 */
public class TimeSocketSvr {
    public static void main(String[] args) {
        try{
            ServerSocket serverSocket=new ServerSocket(123);

            System.out.println("Wait Connect on port:123");
            Socket incomming=serverSocket.accept();

            try{
                InputStream inputStream=incomming.getInputStream();
                OutputStream outputStream=incomming.getOutputStream();

                PrintWriter writer=new PrintWriter(outputStream,true);
                SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH;;mm:ss");
                writer.println(df.format(new Date()));

            }
            finally
            {
                incomming.close();
            }
        }catch (IOException e) {
            e.printStackTrace();
        }
    }
}
